package org.bet.domain;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

@Document
public class Genome extends AbstractSyndicatedData{
	
	private static final long serialVersionUID = 280590801158064799L;
	
	private String species;
	private String access;
	private String version;
	
	@DBRef
	private List<Assembly> assemblies = new ArrayList<Assembly>();
	
	public Genome(String name, Syndicator syndicator) {
		super(name, syndicator);
	}


	public String getSpecies() {
		return species;
	}

	public void setSpecies(String species) {
		this.species = species;
	}

	public String getAccess() {
		return access;
	}

	public void setAccess(String access) {
		this.access = access;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public List<Assembly> getAssemblies() {
		return assemblies;
	}

	public void setAssemblies(List<Assembly> assemblies) {
		this.assemblies = assemblies;
	}

	public Assembly getAssemblyByName(final String assemblyName) {
		
		return (Assembly) CollectionUtils.find(assemblies, new Predicate(){
	
			public boolean evaluate(Object o) {
				Assembly the = (Assembly)o;
				return StringUtils.equals(assemblyName, the.getName());
			}
		});
	}	
	
}
